package com.yoda.controller;

import com.yoda.dto.ArticleDTO;
import com.yoda.entity.YddArticle;
import com.yoda.result.Result;
import com.yoda.service.IYddArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author itcast
 * @since 2023-05-15
 */
@RestController
@RequestMapping("/ydd_article")
public class YddArticleController {
    @Autowired
    private IYddArticleService iYddArticleService;

    /**
     * 文章列表-分页
     * @return
     */
    @GetMapping("/list")
    public Result pageList(ArticleDTO articleDTO){
        return iYddArticleService.pageList(articleDTO);
    }

    /**
     * 根据id删除文章
     * @return
     */
    @GetMapping("/del")
    public Result delete(@RequestParam String id){
        iYddArticleService.removeById(id);
        return Result.success();
    }


    /**
     * 文章添加
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody YddArticle yddArticle){
        return iYddArticleService.add(yddArticle);
    }


    /**
     * 根据id查询文章
     * @return
     */
    @GetMapping("/rowInfo")
    public Result getById(@RequestParam String id){
        return iYddArticleService.getById(id);
    }

    /**
     * 修改文章
     * @return
     */
    @PostMapping("/update")
    public Result updateArticle(@RequestBody YddArticle yddArticle){
        return iYddArticleService.updateArticle(yddArticle);
    }

}

